package register

import (
	"context"
	"github.com/xxl-job/xxl-job-executor-go"
	"mrshen_xxljob_demo/internal/config"
	"mrshen_xxljob_demo/internal/logic"
	"mrshen_xxljob_demo/internal/svc"
)

func StartRocketConsumer(cxt context.Context, svc *svc.ServiceContext, c config.Config) error {
	XxlJobClient := xxl.NewExecutor(
		xxl.ServerAddr(c.XxlJobConf.ServerAddr),
		xxl.AccessToken(c.XxlJobConf.AccessToken), //请求令牌(默认为空)
		xxl.RegistryKey(c.XxlJobConf.RegistryKey), //执行器名称
	)
	XxlJobClient.Init()
	// 注册任务 NewDemo01logic
	logic.NewDemo01logic(cxt, svc)
	XxlJobClient.RegTask("task.test", logic.Demo01)

	err := XxlJobClient.Run()
	if err != nil {
		return err
	}
	return nil
}
